package net.csdn.business.mirror.config;

import lombok.extern.slf4j.Slf4j;
import net.csdn.business.mirror.common.Constants;
import net.csdn.business.mirror.listen.TasksChangeListener;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class RedisMessageReceiver {
    @Autowired
    private TasksChangeListener tasksChangeListener;

    // 重建定时任务
    public void onReceiveMessage(String message, String channel) {
        log.info("Received message: {} from channel: {}", message, channel);
        if (StringUtils.equals(channel, Constants.LOCAL_CACHE_UPDATE_CHANNEL)) {
            if (StringUtils.equals(message, Constants.LOCAL_CACHE_UPDATE_MSG)) {
                tasksChangeListener.changeTasks();
            }
        }
    }
}
